package com.zgm.ch03.example1;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

/**
 *  //3-28
 * 在注入到使用集合
 * @author zgm
 *
 */
public class CollectionDemo {

	private Map map;
	private Properties properties;
	private Set set;
	private List list;
	
	public static void main(String[] args){
//		BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("/WebRoot/WEB-INF/classes/com/zgm/ch03/example1/example1-context.xml"));
//		BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("\WEB-INF\classes\com\zgm\ch03\example1\example1-context.xml"));
		BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("/META-INF/spring/ch03/example1/example1-context.xml"));
		
		CollectionDemo collectionDemo = (CollectionDemo) beanFactory.getBean("collectionDemo");
		collectionDemo.displayInfo();
		
	}
	
	public void displayInfo(){
		Iterator i = map.keySet().iterator();
		System.out.println("Map： \n");
		while(i.hasNext()){
			Object key = i.next();
			System.out.println("Key: " + key + " -value: " + map.get(key));
		}
		
		System.out.println("Properties： \n");
		i = properties.keySet().iterator();
		while(i.hasNext()){
			Object key = i.next();
			System.out.println("Key: " + key + " -value: " + properties.get(key));
		}
		
		System.out.println("Set： \n");
		i = set.iterator();
		while(i.hasNext()){
			System.out.println("value" + i.next());
		}
		
		System.out.println("List： \n");
		i = list.iterator();
		while(i.hasNext()){
			System.out.println("value" + i.next());
		}
	}
	
	
	public void setMap(Map map) {
		this.map = map;
	}
	public void setProperties(Properties properties) {
		this.properties = properties;
	}
	public void setSet(Set set) {
		this.set = set;
	}
	public void setList(List list) {
		this.list = list;
	}
	
	
}
